package com.atech.ebayadmin.common.struts;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7556286645055474703L;
	protected String message = "";
	private static final Log log = LogFactory.getLog(BaseAction.class);
    public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public ActionContext getContext() {
		return ActionContext.getContext();
	}
	
	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}
	public HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}
	public Map getRequestMap() {
		return (Map)this.getContext().get("request");
	}
	public Map getSession() {
		return ServletActionContext.getContext().getSession();
	}
	
	public Map getApplication() {
		return this.getContext().getApplication();
	}

	/**
	 * 公用的处理异常方法，如不适合，可自己定义
	 * @param e 
	 */
	public String handleException(Exception e) {
		log.info("进入到baseAction的handleException方法");
		e.printStackTrace();
		return ERROR;
	}
	@Override
    public String execute() throws Exception{   
//      if("logo".equals(getUsername())){   
//          return SUCCESS;   
//      }else{   
//          throw new SQLException("用户名不正确");   
//      } 
    	log.info("进入到action的execute方法");
    	log.error("获取到action的execute方法的异常");
        throw  new java.lang.Exception("系统错误");   
    } 
}
